﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QLTV_Public;

namespace QLTV_Data
{
   public class NguoiDung_Data
    {
       KetNoiCSDL_Data kn = new KetNoiCSDL_Data();
       public int DoiMatKhau(NguoiDung_Public tenDn, NguoiDung_Public matKhau)
       {
           int n = 2;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@Username";
           value[0] = tenDn.Username;
           name[1] = "@Password";
           value[1] = matKhau.Password;
           return kn.update("DoiMatKhau", name, value, n);
       }
       public DataTable DangNhap_QuanLy(NguoiDung_Public tenDn,NguoiDung_Public matKhau)
       {
           int n = 2;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@Username";
           value[0] = tenDn.Username;
           name[1] = "@Password";
           value[1] = matKhau.Password;
           return kn.LayDuLieu("DangNhap_QuanLy",name,value,n);
       }
       public DataTable DangNhap_NhanVien(NguoiDung_Public tenDn, NguoiDung_Public matKhau)
       {
           int n = 2;
           string[] name = new string[n];
           object[] value = new object[n];
           name[0] = "@Username";
           value[0] = tenDn.Username;
           name[1] = "@Password";
           value[1] = matKhau.Password;
           return kn.LayDuLieu("DangNhap_NhanVien", name, value, n);
       }
       public DataTable LayDuLieu()
       {
           return kn.LayDuLieu("Load_tbl_NguoiDung");
       }
       public DataTable TaoBang(string sql)
       {
           return kn.taobang(sql);
       }
       public int Insert_NguoiDung(NguoiDung_Public username,NguoiDung_Public password,NguoiDung_Public hoTen,NguoiDung_Public ngaySinh,NguoiDung_Public gioiTinh,NguoiDung_Public soCMT,NguoiDung_Public diaChi,NguoiDung_Public maNhom,NguoiDung_Public chucDanh,NguoiDung_Public dienThoai,NguoiDung_Public email)
       {
           int Nparameter = 11;
           string[]name =new string[Nparameter];
           object[]value=new object[Nparameter];
           name[0] = "@Username";
           value[0] = username.Username;
           name[1] = "@Password";
           value[1] = password.Password;
           name[2] = "@HoTen";
           value[2] = hoTen.HoTen;
           name[3] = "@NgaySinh";
           value[3] = ngaySinh.NgaySinh;
           name[4] = "@GioiTinh";
           value[4] = gioiTinh.GioiTinh;
           name[5]="@SoCMT";
           value[5]=soCMT.SoCMT;
           name[6] = "@DiaChi";
           value[6] = diaChi.DiaChi;
           name[7] = "@MaNhom";
           value[7] = maNhom.MaNhom;
           name[8] = "@ChucDanh";
           value[8] = chucDanh.ChucDanh;
           name[9] = "@DienThoai";
           value[9] = dienThoai.DienThoai;
           name[10] = "@Email";
           value[10] = email.Email;
           return kn.update("Insert_NguoiDung",name,value,Nparameter);
       }
       public int Update_NguoiDung(NguoiDung_Public maNV,NguoiDung_Public username, NguoiDung_Public password, NguoiDung_Public hoTen, NguoiDung_Public ngaySinh, NguoiDung_Public gioiTinh,NguoiDung_Public soCMT, NguoiDung_Public diaChi, NguoiDung_Public maNhom, NguoiDung_Public chucDanh, NguoiDung_Public dienThoai, NguoiDung_Public email)
       {
           int Nparameter = 12;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@MaNV";
           value[0] = maNV.MaNV;
           name[1] = "@Username";
           value[1] = username.Username;
           name[2] = "@Password";
           value[2] = password.Password;
           name[3] = "@HoTen";
           value[3] = hoTen.HoTen;
           name[4] = "@NgaySinh";
           value[4] = ngaySinh.NgaySinh;
           name[5] = "@GioiTinh";
           value[5] = gioiTinh.GioiTinh;
           name[6]="@SoCMT";
           value[6]=soCMT.SoCMT;
           name[7] = "@DiaChi";
           value[7] = diaChi.DiaChi;
           name[8] = "@MaNhom";
           value[8] = maNhom.MaNhom;
           name[9] = "@ChucDanh";
           value[9] = chucDanh.ChucDanh;
           name[10] = "@DienThoai";
           value[10] = dienThoai.DienThoai;
           name[11] = "@Email";
           value[11] = email.Email;
           return kn.update("Update_NguoiDung", name, value, Nparameter);
       }
       public int Delete_NguoiDung(NguoiDung_Public maNV)
       {
           int Nparameter = 1;
           string[] name = new string[Nparameter];
           object[] value = new object[Nparameter];
           name[0] = "@MaNV";
           value[0] = maNV.MaNV;
           return kn.update("Delete_NguoiDung", name, value, Nparameter);
       }
    }
}
